<template>
    <div>
        <div class="back-color"></div>
        <div style="z-index: 2;position: relative;">
            <div class="usermsg">
                <img :src="this.$store.getters.auth('himg')"/>
                <div>{{this.$store.getters.auth('nickname')}}</div>
            </div>
            <!--订单列表-->
            <div>
                <div class="content-tips" v-if="false">目前暂无课程订单</div>
                <div class="content" v-for="(i, index) in alllist" :key="index">
                    <div class="top">
                        <div>订单号：{{i.order_no}}</div>
                        <div>{{i.status}}</div>
                        <div class="clear"></div>
                    </div>
                    <div class="msg">
                        <div>
                            <img :src="i.course.teacher_img"/>
                        </div>
                        <div>
                            <span>{{i.course.title}}</span>
                            <span class="clear"></span>
                        </div>
                        <span class="clear"></span>
                    </div>
                    <div class="price">
                        <div style="float: left">
                            已付款：<span style="color: #f0341d;">￥{{i.status !== '已支付' ? i.fee_order : i.fee_tail + i.fee_order}}</span>
                        </div>
                        <div style="float: right">
                            订金：<span style="color: #f0341d;">￥{{i.fee_order}}</span>&nbsp;&nbsp;
                            尾款：<span style="color: #f0341d;">￥{{i.fee_tail === -1 ? '待定': i.fee_tail}}</span>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <div class="allbut">
                        <span @click="addNeed('评价', i.course.id)" v-show="i.status === '完成'">评价</span>
                        <span @click="goview(i.id)">订单详情</span>
                        <span @click="addNeed('课程需求', i.course.id)">课程需求</span>
                        <span v-show="i.status === '成团'" @click="add(index)">支付尾款</span>
                    </div>
                  <!--支付-->
                  <div class="main-kefu" v-show="isKefu[index]">
                    <div class="main-more">
                      <p class="title">
                        <span>请选择支付方式</span><br/>
                        <span>人数过半即众筹成功，余款在封团后3天内支付。 若不成功，预订金原路足额返还。</span>
                        <span class="iconfont icon-untitled94" @click="aloseSel(index)"></span>
                      </p>
                      <p class="mimg"><img src="../../assets/school/puyweixin.png" alt=""><span class="iconfont icon-gou"></span></p>
                      <p class="mbtn" @click="addPay(i.id, index)">确认支付￥{{i.fee_tail}}</p>
                    </div>
                  </div>
                </div>
            </div>
          <div class="tips">侃侃电商学院</div>
          <div class="feedback" @click="gofeed">问题反馈</div>
        </div>
        <div class="layer" v-show="layershow">
            <div class="mask" @click="layershow = false"></div>
            <div class="content">
                <div class="title">{{atitle}}</div>
                <div class="text">
                    <textarea :placeholder="'请输入您的' + atitle" v-model="searchmsg.recommend_course"></textarea>
                </div>
                <div class="bot" @click="select" v-if="atitle === '课程需求'">提交</div>
                <div class="bot" @click="addReplay" v-else>提交</div>
            </div>
        </div>
        <tab-ber :current="3"></tab-ber>
    </div>
</template>

<script>
import TabBer from '../public/tabber'
import msgbox from '@/common/msgbox.js'
import { Toast } from 'mint-ui'
import g from '../../common/g'

export default {
  components: {TabBer},
  name: 'index',
  data: function () {
    return {
      layershow: false,
      isKefu: {},
      atitle: '',
      page: 1,
      rid: '',
      alllist: [],
      searchmsg: {
        recommend_teacher: '',
        recommend_course: ''
      }
    }
  },
  mounted () {
    this.getView()
  },
  methods: {
    aloseSel (index) {
      this.$set(this.isKefu, index, false)
    },
    addReplay () {
      let that = this
      this.layershow = true
      this.atitle = '评论'
      this.$g.ajax({
        path: 'coursecomments/add/' + that.rid,
        method: 'post',
        data: {
          content: that.searchmsg.recommend_course
        },
        cbSuccess: function () {
          Toast({
            message: '评论成功,正在审核中...',
            position: 'bottom',
            duration: 1000
          })
          that.layershow = false
          that.searchmsg.recommend_course = ''
        },
        cbError: function (data) {
          let msg = msgbox.get(data.msg)
          Toast({
            message: msg,
            position: 'bottom',
            duration: 1000
          })
        }
      })
    },
    add (index) {
      if (this.isKefu[index] === undefined) {
        this.$set(this.isKefu, index, false)
      }
      this.$set(this.isKefu, index, true)
    },
    addPay (val, index) {
      let that = this
      g.ajax({
        path: 'courseordersubs/pay/' + val,
        methods: 'post',
        cbSuccess (res) {
          /* eslint-disable no-undef */
          WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
              'appId': 'wx4999af4af069bec3',
              'timeStamp': res.memo.timeStamp,
              'nonceStr': res.memo.nonceStr,
              'package': res.memo.package,
              'signType': res.memo.signType,
              'paySign': res.memo.paySign
            },
            function (wxres) {
              if (wxres.err_msg === 'get_brand_wcpay_request:ok') {
                that.$router.push('/paidsucc/' + that.alllist[index].fee_tail)
              } else if (wxres.err_msg === 'get_brand_wcpay_request:cancel') {
                Toast({
                  message: '已取消支付',
                  position: 'bottom',
                  duration: 1500
                })
              } else {
                Toast({
                  message: '支付失败',
                  position: 'bottom',
                  duration: 1500
                })
              }
            }
          )
        },
        cbError (data) {
          let msg = msgbox.get(data.msg)
          Toast({
            message: msg,
            position: 'bottom',
            duration: 1000
          })
        }
      })
    },
    gofeed () {
      this.$router.push('/users/feedback')
    },
    goview (id) {
      this.$router.push('/order/view/' + id)
    },
    select () {
      let that = this
      this.$g.ajax({
        path: 'Courseneeds/add',
        method: 'post',
        data: that.searchmsg,
        cbSuccess: function () {
          Toast({
            message: '提交成功',
            position: 'bottom',
            duration: 1000
          })
          that.layershow = false
          that.searchmsg.recommend_course = ''
        },
        cbError: function (data) {
          let msg = msgbox.get(data.msg)
          Toast({
            message: msg,
            position: 'bottom',
            duration: 1000
          })
        }
      })
    },
    addNeed (val, id) {
      this.layershow = true
      this.atitle = val
      this.rid = id
    },
    getView () {
      let that = this
      this.$g.ajax({
        path: 'courseorders/index/' + this.page,
        method: 'post',
        cbSuccess: function (data) {
          that.alllist = data.memo.list
          for (let i in that.alllist) {
            if (that.alllist[i].status === 'nopay') {
              that.alllist[i].status = '未支付'
            }
            if (that.alllist[i].status === 'paid') {
              that.alllist[i].status = '已支付'
            }
            if (that.alllist[i].status === 'cancel') {
              that.alllist[i].status = '取消'
            }
            if (that.alllist[i].status === 'completed') {
              that.alllist[i].status = '完成'
            }
            if (that.alllist[i].status === 'create') {
              that.alllist[i].status = '成团'
            }
            if (that.alllist[i].status === 'order') {
              that.alllist[i].status = '定金'
            }
          }
        },
        cbError: function (data) {
          let msg = msgbox.get(data.msg)
          Toast({
            message: msg,
            position: 'bottom',
            duration: 1000
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
  .main-kefu{
    width: 100%;
    height: 100%;
    background: rgba(178,178,178,0.6);
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 999;
    text-align: center;
    .main-more{
      width: 100%;
      background: white;
      min-height: 100px;
      position: absolute;
      bottom: 50px;
      .mbtn{
        width: 94%;
        line-height: 40px;
        border-radius: 5px;
        float: left;
        margin-left: 3%;
        margin-bottom: 10px;
        color: white;
        background: #0033a0;
        font-size: 13px;
        margin-top: 20px;
      }
      .title{
        margin-top: 15px;
        position: relative;
        padding: 0 3%;
        span:nth-of-type(1){
          font-weight: 700;
          font-size: 16px;
        }
        span:nth-of-type(2){
          font-size: 12px;
          color: #666;
        }
        span:nth-of-type(3){
          position: absolute;
          right: 3%;
          top: 0;
          color: #666;
          font-size: 14px;
        }
      }
      .mimg{
        margin-top: 10px;
        img{
          float: left;
          margin-left: 3%;
        }
        span{
          float: right;
          margin-right: 3%;
          color: #0033a0;
          line-height: 30px;
          font-size: 20px;
        }
      }
    }
    i{
      font-size: 40px;
      color: white;
      line-height: 60px;
    }
  }
    .back-color{
        position: absolute;
        height: 100%;
        background-color: #f3f3f3;
        width: 100%;
        z-index: 1
    }
    .layer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        z-index: 999;
        .mask {
            background: rgba(153, 153, 153, 0.5);
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            z-index: 1;
        }
        .content {
            position: relative;
            width: 80%;
            background: #fff;
            margin: 30% auto;
            padding: 30px;
            z-index: 2;
            .title{
                text-align: center;
                font-size: 14px;
                font-weight: bold;
            }
            .text{
                margin-top: 20px;
                width: 100%;
                textarea{
                    width: 97.6%;
                    resize: none;
                    border: 1px solid #e5e5e5;
                    height: 200px;
                    padding: 6px 0 6px 6px;
                }
                textarea::placeholder{
                    color: #999999;
                }
            }
            .bot{;
                margin-top: 20px;
                width: 100%;
                height: 40px;
                font-size: 16px;
                text-align: center;
                line-height: 40px;
                background-color: #0a51cc;
                color: #ffffff;
            }
        }
    }
    /*.tips{*/
        /*text-align: center;*/
        /*margin-top: 20px;*/
        /*font-size: 22px;*/
        /*font-weight: bold;*/
        /*color: #d4d8d8;*/
    /*}*/
    .content-tips {
        text-align: center;
        font-size: 12px;
        color: #e5e5e5;
        margin: 10px 0;
        padding: 20px 0;
        background-color: #ffffff;
    }
    .content{
        margin: 10px 0;
        background-color: #ffffff;
        .top{
            font-size: 14px;
            padding: 10px 10px;
            border-bottom: 1px solid #e5e5e5;
            div:nth-of-type(1){
                float: left;
                color: #999999;
                position: relative;
                top: 2px;
            }
            div:nth-of-type(2){
                float: right;
                font-weight: bold;
                color: #0640a1;
                font-size: 16px;
            }
        }
        .msg{
            background-color: #fafafa;
            padding: 10px 10px;
            div{
                float: left;
            }
            div:nth-of-type(1){
                width: 28%;
                height: 70px;
            }
            div:nth-of-type(2){
                margin-left: 6px;
                width: 70%;
                height: 70px;
                font-size: 16px;
                span:nth-of-type(1){
                    display: block;
                    min-height: 44px;
                    line-height: 24px;
                    margin: 4px 0 4px 0;
                }
            }
            img{
                width: 100%;
                height: 100%;
            }
        }
        .price{
            text-align: right;
            padding: 10px;
            font-size: 14px
        }
        .allbut{
            padding: 14px 10px 16px 10px;
            border-top: 1px solid #e5e5e5;
            text-align: right;
            span{
                margin-left: 10px;
                padding: 6px 12px;
                background-color: #ffffff;
                border: 1px solid #0640a1;
                color: #0640a1;
                border-radius: 14px;
                font-size: 14px;
            }
            span:last-of-type{
                background-color: #0640a1;
                border: 1px solid #ffffff;
                color: #ffffff;
            }
        }
    }
    .usermsg {
        padding: 30px 10px;
        text-align: center;
        font-size: 14px;
        font-weight: bold;
        background-color: #ffffff;
        div:nth-of-type(1) {
            margin-top: 10px;
            color: #202020;
        }
        img:nth-of-type(1) {
            width: 80px;
            height: 80px;
            border-radius: 40px;
        }
    }
  .tips{
    text-align: center;
    padding-top: 20px;
    font-size: 22px;
    font-weight: bold;
    color: #d4d8d8;
    background: rgba(244,244,244,0.8);
  }
  .feedback{
    text-align: right;
    font-size: 12px;
    padding-right: 14px;
    color: #ababab;
    background: rgba(244,244,244,0.8);
    padding-bottom: 20px;
    width: 100%;
    box-sizing: border-box;
  }
</style>
